package com.itheima.demo003;

import java.util.ArrayList;

public class test32_ {
    public static void main(String[] args) {
        /*ArrayList增删改查
        添加:boolean add(E e)
        删除:boolean remove(E e)
            E remove(int index)
        修改:E set(int index, E e)
        查询:E get(int index)
        获取长度:int size()
         */

        //1.创建一个集合
        ArrayList<String> list = new ArrayList<>();

        //2.添加元素
        //boolean result = list.add("aaa");
        //System.out.println(result);//true

        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        //System.out.println(list);//[aaa, bbb, ccc]

        /*
        3.删除元素
        boolean result1 = list.remove("aaa");
        System.out.println(result1);

        boolean result2 = list.remove("bbb");
        System.out.println(result2);
         */


        //根据索引删除元素
        //String str = list.remove(0);
        //System.out.println(str);//bbb

        /*
        4.修改元素
        String result = list.set(0,"ddd");
        System.out.println(result);
         */


        /*
        5.查询元素
        String result = list.get(0);
        System.out.println(result);
         */


        //6.遍历
        for (int i = 0; i < list.size(); i++) {
            //i 索引
            //list.get(i) 元素
            String str = list.get(i);
            System.out.println(str);
        }

        System.out.println(list);
    }
}
